#include "MainWindow.h"
#include "ui_MainWindow.h"



#include <Defines.h>
#include <CampaignItem.h>
#include <CharacterItem.h>
#include <ItemFactory.h>



#include <XmlSerializer.h>
#include <FileHandler.h>



#include <QMessageBox>
#include <QFileDialog>
#include <QTreeView>
#include <QTimer>



MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    FileHandler::installSerializer(new XmlSerializer(this));

    ui->setupUi(this);
}



MainWindow::~MainWindow()
{
    delete ui;
}



void MainWindow::closeEvent(QCloseEvent *e)
{
    on_actionQuit_triggered();

    QMainWindow::closeEvent(e);
}



void MainWindow::resizeEvent(QResizeEvent *e)
{
    QMainWindow::resizeEvent(e);
}



void MainWindow::on_tabWidget_tabCloseRequested(int index)
{
    ui->tabWidget->onClose(index);
}



void MainWindow::on_actionNew_Character_triggered()
{
    ui->tabWidget->onNew(TabWidget::CharacterTab);
}



void MainWindow::on_actionNew_Campaign_triggered()
{
    ui->tabWidget->onNew(TabWidget::CampaignTab);
}



void MainWindow::on_actionOpen_triggered()
{
    ui->tabWidget->onOpen();
}



void MainWindow::on_actionSave_triggered()
{
    ui->tabWidget->onSave();
}



void MainWindow::on_actionSave_As_triggered()
{
    ui->tabWidget->onSaveAs();
}



void MainWindow::on_actionClose_Current_triggered()
{
    int index = ui->tabWidget->currentIndex();
    on_tabWidget_tabCloseRequested(index);
}



void MainWindow::on_actionQuit_triggered()
{
    int tabs = ui->tabWidget->count();
    for (int index = 0; index < tabs; index++)
    {
        on_tabWidget_tabCloseRequested(index);
    }

    close();
}



void MainWindow::on_actionAdd_triggered()
{
    ui->tabWidget->onAdd();
}



void MainWindow::on_actionDelete_triggered()
{
    ui->tabWidget->onDelete();
}



void MainWindow::on_actionCreate_Group_triggered()
{
    ui->tabWidget->onCreateGroup();
}



void MainWindow::on_actionCreate_Item_triggered()
{
    ui->tabWidget->onCreateItem();
}



void MainWindow::on_actionCreate_Reference_triggered()
{
    ui->tabWidget->onCreateReference();
}



